package com.loong.common.mvc;

import com.loong.common.redis.RedisTools;
import com.loong.global.constant.RedisKey;
import com.loong.global.dto.AdminDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;

public class BaseBackendController extends BaseController {

    @ModelAttribute("adminInfo")
    public AdminDTO before(HttpServletRequest request) {
        String paramUserId = request.getParameter("headerUid");
        if (StringUtils.isEmpty(paramUserId)) {
            return null;
        }
        Integer uid = Integer.valueOf(paramUserId);
        AdminDTO adminDTO = RedisTools.valueOperations().get(RedisKey.ADMIN.ADMIN_CACHE + uid, AdminDTO.class);
        return adminDTO;
    }

    public AdminDTO getAdminDTO(){
        AdminDTO adminDTO = new AdminDTO();
        adminDTO.setId(1L);
        adminDTO.setUsername("jack");
        return adminDTO;
    }
}
